import java.awt.Dimension;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;

import edu.umd.cs.piccolo.PCamera;
import edu.umd.cs.piccolo.PCanvas;

public class ColorNamesInfoVis extends PCanvas {
	
	private final int NUM_LAYERS = 3;

	private ColorGridNode[] parentNodes = new ColorGridNode[NUM_LAYERS];
	private BottomColorGridNode childNode;

	private int[] filter;
	
	public ColorNamesInfoVis() {
		PCamera camera = getCamera();
		DbHandler db = new DbHandler();
		filter = new int[2];
		filter[0] = 0;
		filter[1] = 2;
		childNode = new BottomColorGridNode(camera,db,0,1,0,1, filter);
		parentNodes[NUM_LAYERS-1] = new ColorGridNode(camera, db, childNode, 0, 1, 0, 1, filter);
		for(int i=NUM_LAYERS-2;i>=0;i--) {
			parentNodes[i] = new ColorGridNode(camera, db, parentNodes[i+1], 0, 1, 0, 1, filter);
		}
		getLayer().addChild(parentNodes[0]);
		setZoomEventHandler(null);
		setPanEventHandler(null);
		addComponentListener(new ComponentAdapter() {
			@Override
			public void componentResized(ComponentEvent arg0) {
				parentNodes[0].setBounds(getX(), getY(), getWidth() - 1,
						getHeight() - 1);
				parentNodes[0].layoutChildren(null, false);
			}
		});
	}
	
	public void setFilter(int[] filter) {
		this.filter = filter;
		parentNodes[0].setFilter(filter);
	}

	@Override
	public Dimension getPreferredSize() {
		return new Dimension(1280, 720);
	}
}